﻿@model Guline.SupportCMS.Models.Object.Article

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/v1_admin_layout.cshtml";
    List<Guline.SupportCMS.Models.Object.Category> category = ViewBag.CategoryID;
    var icats = Model.ArticleCategorys.Select(m => m.CategoryID).ToList();
}

<h1>
    <a href="@Url.Action("Index")"><i class="icon-arrow-left-3 fg-darker smaller"></i></a>
    Edit Article<small class="on-right"> Sửa bài viết.</small>
</h1>
<div class="clearfix"></div>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Article</legend>
        @Html.HiddenFor(m => m.ID)
        @Html.HiddenFor(m => m.created_Date)
        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Title)
            @Html.ValidationMessageFor(model => model.Title)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Enable)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Enable)
            @Html.ValidationMessageFor(model => model.Enable)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.Image)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Image, new { @readonly = "readonly" })
            <input type="button" id="btnSelectImg" value="Chọn hình" />
            <br />
            <img id="img-logo" src="@Model.Image" style="width: 100px; height: 100px;" />
            @Html.ValidationMessageFor(model => model.Image)

        </div>
        <div class="editor-label">
            Chuyên Mục
        </div>
        <input type="hidden" id="hdid" name="hdname" />
        <div class="editor-field">
            @foreach (var n in category)
            {
              
                <label>
                    <input type="checkbox" id="@n.ID" @(icats.Contains(n.ID) ? "checked" : "")  class="cbox">@n.Name</label>
                foreach (var k in n.Childrens)
                {
                     
                <label>-----<input type="checkbox" id="@k.ID" @(icats.Contains(k.ID) ? "checked" : "") class="cbox"/>@k.Name</label>
                       
                }

            }
        </div>


        <div class="editor-label">
            @Html.LabelFor(model => model.ShortDes)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.ShortDes, new { style = "width:100%;height:150px" })
            @Html.ValidationMessageFor(model => model.ShortDes)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.FullDes)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.FullDes, new { style = "height:300px" })
            @Html.ValidationMessageFor(model => model.FullDes)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.SourceLink)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.SourceLink)
            @Html.ValidationMessageFor(model => model.SourceLink)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.SourceName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.SourceName)
            @Html.ValidationMessageFor(model => model.SourceName)
        </div>

        <div class="editor-label">
        </div>
        <div class="editor-field">
            @Html.HiddenFor(model => model.Order)
            @Html.ValidationMessageFor(model => model.Order)
        </div>


        <div class="editor-label">
            @Html.LabelFor(model => model.AccountID, "Account")
        </div>
        <div class="editor-field">
            @Html.DropDownList("AccountID", String.Empty)
            @Html.ValidationMessageFor(model => model.AccountID)
        </div>



        <input type="submit" class="primary margin20 place-right padding10" value="Edit" />

    </fieldset>
}

<script src="~/ckfinder/ckfinder.js"></script>
<script src="~/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    var ck = CKEDITOR.instances['FullDes'];
    if (ck)//check if instance exist
    {
        CKEDITOR.remove(ck);
    }

    CKEDITOR.replace('FullDes', {
        autoGrow_maxHeight: 500,
        height: 600,
        removePlugins: 'resize',
        enterMode: CKEDITOR.ENTER_BR,
        filebrowserBrowseUrl: '/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl: '/ckfinder/ckfinder.html',
        filebrowserUploadUrl: '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&amp;type=Files',
        filebrowserImageUploadUrl: '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&amp;type=Images',
        filebrowserWindowWidth: 800,
        filebrowserWindowHeight: 500,
        fullPage: true,
        allowedContent: true
    });
</script>
<script>

    $(document).ready(function () {
        $("#btnSelectImg").click(function () {
            var finder = new CKFinder();
            finder.selectActionFunction = function (fileUrl) {
                $('#Image').val(fileUrl);
                $('#img-logo').attr("src", fileUrl)
            };
            finder.popup();
        });

        $(".cbox").change(function () {
            var ten = $("#hdid").val();
            var chuoi = "";
            $(".cbox").each(function (index, item) {

                if ($(item).is(':checked')) {
                    if (chuoi == "") {
                        chuoi = $(item).attr("id");
                    }
                    else {
                        chuoi += "," + $(item).attr("id");
                    }
                }

            });
            $("#hdid").val(chuoi);

        });

    });
</script>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")

}
